'use strict';
import React from 'react';
import {
  Alert,
} from 'react-native';

import Config from '../config';

var isShowUnauthorization = false;

export default class Functions {
  //检测jwt
  static unauthorizationAlert(prePageObj, errorDetail) {
    if(isShowUnauthorization === true) {
      return;
    }
    errorDetail = (errorDetail != undefined && errorDetail != null) ? errorDetail : '您的登录已过期，请重新登录';
    isShowUnauthorization = true;
    Alert.alert('提示', errorDetail, [
        {text:'确定',onPress:()=>{
          prePageObj.gotoPage(Config.pages.login);
          isShowUnauthorization = false;
        }}
      ])
  }

  //检测用户身份
  static verifyAlert(prePageObj, content) {
    let msg = content ? content : '用户未认证';
    Alert.alert('提示', msg, [
        {text:'确认',onPress:()=>{}}
      ])
  }

  //检测用户身份
  static loginInfoUserAlert(prePageObj, content) {
    let msg = content ? content : '你是游客身份';
    Alert.alert('提示', msg, [
        {text:'员工登录',onPress:()=>{prePageObj.gotoPage(Config.pages.login)}},
        {text:'取消',onPress:()=>{}}
      ])
  }

  //退出登录确认提示
  static loginOutSubmit(prePageObj, callback) {
    let msg = "是否确定要退出当前登录?";
    Alert.alert("提示", msg, [
      {text:"确定", onPress:() => callback()},
      {text:"取消", onPress:()=>{}},
    ])
  }
}
